package com.Liuhang.Dao;

import com.Liuhang.JDBC.util;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import static jdk.nashorn.internal.objects.ArrayBufferView.length;

public class verify extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("进入了doGet方法");
        ServletContext context = this.getServletContext();
        String username = (String) req.getParameter("username");
        String passwd = (String) req.getParameter("passwd");
        System.out.println(username+passwd);
        try {
            String sql = "select * from t_emp WHERE name='"+username+"' AND passwd = "+passwd+"";
            System.out.println(sql);
            Statement st = util.getStatement();
            System.out.println(st.executeQuery(sql));
            ResultSet rs = st.executeQuery(sql);
            if(rs.next()){
                context.getRequestDispatcher("/index.html").forward(req,resp);
            }else{
                context.getRequestDispatcher("/passwdErro.html").forward(req,resp);
            }
        } catch (SQLException | ClassNotFoundException throwables) {
            throwables.printStackTrace();
        }

    }

}
